package com.pay.ioopos.support.serialport.custom;

/**
 * 外部串口设备支付工具
 * @author moyq5
 * @since 2022/7/28
 */
public final class SerialPortPayUtils {
    private SerialPortPayUtils() {

    }
    public static void detect() {
        SerialPortPayFactory.detect();
    }
    public static void cancel(SerialPortPayer.CancelState state) {
        SerialPortPayFactory.getPayer().cancel(state, null);
    }
    public static void cancel(SerialPortPayer.CancelState state, String detail) {
        SerialPortPayFactory.getPayer().cancel(state, detail);
    }
    public static void pay(SerialPortPayer.PayState state, String amount) {
        SerialPortPayFactory.getPayer().pay(state, amount, null);
    }
    public static void pay(SerialPortPayer.PayState state, String amount, String detail) {
        SerialPortPayFactory.getPayer().pay(state, amount, detail);
    }

    public static void response(CustomCmdReceive receive, CustomCmdStatus status) {
        CustomSerialPortFactory.find(new SerialPortPayFinder() {
            @Override
            public void onFound(CustomSerialPort serialPort) {
                serialPort.send(new CustomCmdRes(receive.getCmdType(), receive.getSerialNo(), status));
            }
        });
    }

    public static void response(CustomCmdReceive receive, CustomCmdStatus status, String message) {
        CustomSerialPortFactory.find(new SerialPortPayFinder() {
            @Override
            public void onFound(CustomSerialPort serialPort) {
                serialPort.send(new CustomCmdRes(receive.getCmdType(), receive.getSerialNo(), status, message));
            }
        });
    }
}
